<?php
$_this =& $this;

/* @var $_this View */
/* @var $form FormHelper */
/* @var $editForm EditFormHelper */
/* @var $html HtmlHelper */
/* @var $ehtml EHtmlHelper */
/* @var $javascript JavascriptHelper */
/* @var $jqax JqaxHelper */
/* @var $filterBlock FilterBlock */

?><?=$filterBlock->create('Filter', array('url'=>("/{$url_part}/")));?><?php
	if (!$by_client) {
    	$filterBlock->add(
            $form->label('client_id', __d($po_domain, 'client_field', true).':&nbsp;',array('class'=>'filter')).
            $form->select('client_id', $clients_list, null, array('label' => false), '')
    	);
	}
	$filterBlock->add(
        $form->label('from_date', __d($po_domain, 'created_field', true).': '.mb_strtolower(__d(null, 'from_period', true), DEFAULT_CHARSET).'&nbsp;',array('class'=>'filter')).
		$calendar->date('from_date', false, array('size' => '10', 'label' => false)).
		$form->label('to_date', __d(null,'to_period', true).'&nbsp;',array('class'=>'filter')).
		$calendar->date('to_date', false, array('size' => '10', 'label' => false))
	);
    $filterBlock->sep();
	$filterBlock->add(
        $form->label('type', __d($po_domain, 'type_field', true).':&nbsp;',array('class'=>'filter')).
        $form->select('type', $types_list, null, array('label' => false), '')
	);
	$filterBlock->add(
        $form->label('tool', __d($po_domain, 'test_name', true).':&nbsp;',array('class'=>'filter')).
        $form->select('tool', $tools_list, null, array('label' => false), '')
	);
?><?=$filterBlock->end();?><?php

?><br /><?php

if (count($list->rows)) {

?><?=$this->renderElement('pagination', array('paging' => $list->pagination));?><?php

?><table class="table" cellpadding="0"><?php
?><thead><?php
    ?><tr><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'date', 'msg'=>'created', 'domain'=>$po_domain));?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'type', 'msg'=>'type', 'domain'=>$po_domain));?><?php
        ?></th><?php
        if (!$by_client) {
            ?><th class="nw"><?php
                ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'client', 'msg'=>'client', 'domain'=>$po_domain));?><?php
            ?></th><?php
        }
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'amount', 'msg'=>'amount', 'domain'=>$po_domain));?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'author', 'msg'=>'author', 'domain'=>$po_domain));?><?php
        ?></th><?php
		?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'candidate', 'msg'=>'candidate_name', 'domain'=>$po_domain));?><?php
        ?></th><?php
		?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'tool', 'msg'=>'test_name', 'domain'=>$po_domain));?><?php
        ?></th><?php
		?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'report', 'msg'=>'report_name', 'domain'=>$po_domain));?><?php
        ?></th><?php
		?><th class="nw"><?php
            ?><?=__d('clients', 'comment', true);?><?php
        ?></th><?php


    ?></tr><?php
?></thead><?php
?><tbody><?php

    $i = 0;
    foreach ($list->rows as $item) {
        $class = '';
    	if ($i++ % 2 != 0) {
    		$sep = strlen($class) ? ' ' : '';
    		$class .= $sep.'altrow';
    	}
    	$class = strlen($class) ? ' class="'.$class.'"' : '';

        ?><tr <?=$class;?>><?php
    		?><td class="nw"><?php
                ?><?=Date::Short(Date::SQL2UNIX($item[$modelName]['created']));?><?php
            ?></td><?php
    		?><td><?php
                ?><?=h(__d($po_domain, 'type_'.$item[$modelName]['type'], true));?><?php
            ?></td><?php
            if (!$by_client) {
        		?><td class="nw"><?php
                    ?><?=$html->link($item['Client']['name'], "/clients/".$item['Client']['id']."/");?><?php
                ?></td><?php
            }
    		?><td class="nw align-r"><?php
                $amount = $item[$modelName]['amount'];
                if ($item[$modelName]['type'] != 'REFILL_ACCOUNT') {
                    $amount = bc::sub(0, $amount);
                }
                ?><?=$_this->renderElement('sum', array('sum' => $amount));?><?php
            ?></td><?php
    		?><td class="nw"><?php
                if (Auth::o()->is('client_admin')) {
                    if (!empty($item['Admin']['id'])) {
                        ?><span class="additional_msg"><?php
                            ?><?=__d($po_domain, 'admin_for_client', true);?><?php
                        ?></span><?php
                    } elseif (!empty($item['ClientAdmin']['id'])) {
                        ?><?=$html->link($item['ClientAdmin']['name'], "/client-admins/".$item['ClientAdmin']['id']."/");?><?php
                    } else {
                        ?>…<?php
                    }
                } else {
                    if (!empty($item['Admin']['id'])) {
                        ?><?=$html->link($item['Admin']['username'], "/admins/".$item['Admin']['id']."/");?><?php
                        ?><div class="note"><?php
                            ?><?=__d($po_domain, 'admin', true);?><?php
                        ?></div><?php
                    } elseif (!empty($item['ClientAdmin']['id'])) {
                        ?><?=$html->link($item['ClientAdmin']['username'], "/client-admins/".$item['ClientAdmin']['id']."/");?><?php
                        ?><div class="note"><?php
                            ?><?=__d($po_domain, 'client_admin', true);?><?php
                        ?></div><?php
                    } else {
                        ?>…<?php
                    }
                }
            ?></td><?php
    		?><td class="nw"><?php
        		if (!empty($item['Candidate']['id'])) {
        		    if (Auth::o()->is('client_admin') && ! Auth::o()->is('CANDIDATES')) {
                        ?><?=$item['Candidate']['name'].' '.$item['Candidate']['surname'];?><?php
        		    } else {
                        ?><?=$html->link($item['Candidate']['name'].' '.$item['Candidate']['surname'], "/candidates/".$item['Candidate']['id']);?><?php
        		    }
        		} else {
                    ?>—<?php
        		}
            ?></td><?php
    		?><td class="nw"><?php
        		if (!empty($item['Test']['id'])) {
                    ?><?=$item['Test']['name'];?><?php
        		} else {
                    ?>—<?php
        		}
            ?></td><?php
    		?><td class="nw"><?php
        		if (!empty($item['Reporting']['Report']['id'])) {
                    ?><?=$item['Reporting']['Report']['name'];?><?php
        		} else {
                    ?>—<?php
        		}
            ?></td><?php
    		?><td><?php
        		if (!empty($item['Pass']['comment'])) {
                    ?><?=$item['Pass']['comment'];?><?php
        		} else {
                    if ($item[$modelName]['type'] == 'REFILL_ACCOUNT') {
                        ?>…<?php
        		    } else {
                        ?>—<?php
        		    }
        		}
            ?></td><?php

    	?></tr><?php
    }

?></tbody><?php
?></table><?php

?><?=$this->renderElement('pagination', array('paging' => $list->pagination));?><?php

} else {
    ?><span class="additional_msg"><?php
        ?><?=__d($po_domain, 'List is empty', true);?><?php
    ?></span><?php
}

?>